#region imported Namespaces
using System;
using System.Data;
using System.Text;
using BO = PHSRAG.Insight21.BusinessObjects;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
#endregion

namespace PHSRAG.Insight21.Personnel
{
	#region Class PayrollException
	/// <summary>
	/// The PayrollException class is the facade over the details for a single payroll exception
	/// </summary>
	public class PayrollException : BO.BusinessObject
	{
		#region Constants
		private const string PayrollExceptionKey			= "PayrollException_BEEF0A8B-1222-4CB4-BBEB-59DAD509370C";
		//Constants to hold the column names
		private const string JobMapIdColumnName							= "EmployeeJobMapId";
		private const string EmployeeNumberColumnName					= "EmployeeNumber";
		private const string EmployeeNameColumnName						= "EmployeeName";
		private const string RecordNumberColumnName						= "RecordNumber";
		private const string EffectiveDateColumnName					= "NewGroupEffectiveDate";
		private const string ExpirationDateColumnName					= "NewStackEndDate";
		private const string ExceptionMessageColumnName					= "Exception";
		#endregion

		#region Instance variables
		private DataRow exceptionRow;
		#endregion

		#region Public Properties
		/// <summary>
		/// Get the job map id associated with the employee.
		/// It is a non nullable field.
		/// </summary>
		public int EmployeeJobMapId
		{
			get
			{
				return (int)exceptionRow[JobMapIdColumnName];
			}
		}
		/// <summary>
		/// Get the employee's name
		/// It is a non nullable field.
		/// </summary>
		public string EmployeeName
		{
			get
			{
				return exceptionRow[EmployeeNameColumnName].ToString();
			}
		}
		/// <summary>
		/// Get the EmployeeNumber. Return an empty string if the employee has no employee number associated.
		/// </summary>
		public string EmployeeNumber
		{
			get
			{
				object employeeNumber = exceptionRow[EmployeeNumberColumnName];
				return (employeeNumber == DBNull.Value) ? string.Empty : employeeNumber.ToString();
			}
		}
		/// <summary>
		/// Get the RecordNumber assocaited with the employee
		/// It is a non nullable field.
		/// </summary>
		public int RecordNumber
		{
			get
			{
				return (int)exceptionRow[RecordNumberColumnName];
			}
		}
		/// <summary>
		/// Get the fund effective date of the employee's salary.
		/// Return an empty string if no effective date is assigned to the salary.
		/// </summary>
		public string EffectiveDate
		{
			get
			{
				object effectiveDate = exceptionRow[EffectiveDateColumnName];
				return (effectiveDate == DBNull.Value) ? 
					string.Empty : ((DateTime)effectiveDate).ToString("MM/dd/yyyy");
			}
		}
		/// <summary>
		/// Get the fund expiration date of the employee's salary.
		/// Return an empty string if no expiration date is assigned to the salary.
		/// </summary>
		public string ExpirationDate
		{
			get
			{
				object expirationDate = exceptionRow[ExpirationDateColumnName];
				return (expirationDate == DBNull.Value) ? 
					string.Empty : ((DateTime)expirationDate).ToString("MM/dd/yyyy");
			}
		}
		/// <summary>
		/// Get the exception message
		/// </summary>
		public string Exception
		{
			get
			{
				object exception = exceptionRow[ExceptionMessageColumnName];
				return (exception==DBNull.Value) ? 
					string.Empty: exception.ToString();
			}
		}
		#endregion

		#region Constructor
		/// <summary>
		/// Initialize the base class with the specified cache policy, and save the DataRow in this instance.
		/// Build the Exception Message.
		/// </summary>
		/// <param name="cachePolicy">Prevalent cache policy</param>
		/// <param name="dataRow">DataRow containing exception data</param>
		public PayrollException(ICachePolicy cachePolicy,DataRow dataRow) : base (cachePolicy)
		{
			exceptionRow = dataRow;
			//GenerateExceptionMessage();
		}		
		#endregion

		#region BusinessObject Methods
		/// <summary>
		/// Cache the PayrollException instance using the prevalent cache policy
		/// </summary>
		public override void Cache()
		{
			CachePolicy.Cache(PayrollExceptionKey,this);
		}
		/// <summary>
		/// Remove the PayrollException instance from the cache using the prevalent cache policy
		/// </summary>
		public override void UnCache()
		{
			CachePolicy.UnCache(PayrollExceptionKey);
		}
		/// <summary>
		/// This method is not used and only exists to satisfy interface requirements.
		/// </summary>
		public override void Load(string connectionString, params object[] args)
		{			
			throw new Exception("PayrollException cannot be directly loaded.");
		}
		#endregion

	}
	#endregion
}